package com.ak.server.platform.service.impl;

import com.ak.common.entity.system.TenantApplication;
import com.ak.common.exception.AKException;
import com.ak.server.platform.mapper.TenantApplicationMapper;
import com.ak.server.platform.service.ITenantApplicationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TenantApplicationServiceImpl extends ServiceImpl<TenantApplicationMapper, TenantApplication> implements ITenantApplicationService {


    /**
     * 租户分配子系统
     *
     * @param tenantCode
     * @param appCodes
     * @return
     */
    @Override
    @Transactional
    public boolean authApplication(String tenantCode, String appCodes) {
        try {
            this.baseMapper.deleteByTenantCodeOrAppCode(tenantCode, null);
            this.baseMapper.batchTenantApplication(tenantCode, Arrays.asList(appCodes.split(",")));
            return true;
        } catch (AKException e) {
            throw new AKException("为租户分配子系统异常");
        }
    }


}
